<template>
	<view class="margin-sm">

		<view v-if="dateList.length==0" class="margin-top-sm">
			<blues-empty img="msg" text="暂无数据">

			</blues-empty>
		</view>
		<view v-for="(item,index) in dateList" class="radius bg-green">
			<view class="padding-sm  margin-top-sm" @click="getInfo(item,index)"> {{item.stadate}}</view>
			<view v-show="item.data!=null&&item.open">

				<view v-for="(item2,index2) in item.data" class="car">
					<view style="border: .5px solid #fff;margin: 0px 10px"></view>
					<view class=" padding">
						<view class="clearfix">
							<text style="font-size: 14px;font-weight: 900;">项目:{{ item2.content2.areaName }}</text>
							<text style="font-size: 12px;margin-left: 5px">天数:{{item2.days}}</text>
							<text style="font-size: 12px;margin-left: 5px">次数:{{ item2.number }}
							</text>
							<button v-if="item2.pushToParents!=1" class="cu-btn block bg-red" style="float: right; "
								@click="bianji(item2,1)">
								未推送
							</button>
							<button v-if="item2.pushToParents==1" size="mini" style="float: right;"
								class="cu-btn block bg-blue" type="success" @click="bianji(item2,0)">已推送
							</button>
						</view>


						<view :gutter="2">
							<text :text="4">用户:</text>
							<text :text="16">
								{{ getname(item2.createBy) }}
							</text>
							<br>
							创建日期:{{ item2.createTime }}
							<br>
						</view>
						<view :gutter="5">
							备注:{{ item2.remarks }}
						</view>

						<view :gutter="5">
							家长反馈:
							<view v-for="s in item2.daysAndFk">
								<text>第{{ s.index }}天</text>
								<text>{{ s.ok == 1 ? '已打卡' : '未打卡' }}</text>
								<text v-if="s.time">{{ s.time }}</text>
								<view v-if="s.img!=null&&s.img.length>0">
									反馈图片:
									<image v-if="s.img!=null&&s.img.length>0"
										:preview-src-list="pictureProcessing(s.img)" :src="s.img[0].url"
										style="height: 30px;width: 30px"></image>
								</view>
								<view v-if="s.video!=null&&s.video.length>0">
									反馈视频:
									<view v-for="(s2,index) in s.video">
										<a :href="s2.url" target="_blank" type="primary">视频{{ index + 1 }}</a>
									</view>
								</view>

								<view v-if="s.text">反馈文字:{{ s.text }}</view>
								<view v-for="sdfsd in s.textList">
									{{ sdfsd.name }}: {{ sdfsd.text }}--- {{ sdfsd.time }}
								</view>
								<hr style="margin: 3px;color: white;">

							</view>
						</view>
					</view>
				</view>
			</view>
		</view>

		<view class="floating-div juzhong bg-blue" @click="addSysOfflineClass">
			<uni-icons type="plusempty" size="30" color="#fff" style="font-weight: bold;"></uni-icons>
		</view>
	</view>
</template>

<script>
	import {
		formatterUserName,
		getcommon
	} from "../../../utils/common";
	import {
		customWorkAPI,
		doInsert,
		doUpdate,
		getById,
		getDateList
	} from "@/api/lpc/classassignments/LpcClassAssignmentsManagementApi";
	import {
		isJson,
		isNull
	} from "@/utils/validate";
	export default {
		data() {
			return {
				dateList: [],
				query: {
					customerId: null,
				}

			}
		},
		onLoad(e) {
			console.log(e);
			if (e.customerId != null) {
				this.query.customerId = e.customerId
			}
			this.init()
		},
		methods: {

			addSysOfflineClass() {
				uni.navigateTo({
					url: "/pages/lpc/work/edit?customerId=" + this.query.customerId + "&name=" + this.query
						.customerId
				})
			},
			init() {
				this.getDateList()

			},
			getList(data) {

			},
			getname(id) {
				return formatterUserName(id)
			},
			getInfo(data, index) {
				data.open = !data.open
				console.log(data.open);
				if (!data.open) {
					this.$forceUpdate()
					return
				}
				this.getdata({
					customerId_EQ: this.query.customerId,
					staDate_EQ: this.dateList[index].stadate,
					pageNo: 1,
					pageSize: 100,
					web: 1,
				}, index)
			},
			async getDateList() {
				const {
					success,
					msg,
					data
				} = await getDateList({
					cid: this.query.customerId
				});
				if (success) {
					this.dateList = data
					this.dateList.reverse()
					for (let s of this.dateList) {
						s.open = false
					}
					if (this.dateList.length > 0) {
						this.getdata({
							customerId_EQ: this.query.customerId,
							staDate_EQ: this.dateList[0].stadate,
							pageNo: 1,
							pageSize: 100,
							web: 1,
						}, 0)
					}
				}
			},
			async bianji(string, a) {
				string.pushToParents = a
				if (typeof string.content != 'string') {
					string.content = JSON.stringify(string.content)
				} else {
					string.content = string.content
				}
				const {
					success,
					msg
				} = await doUpdate(string);
				this.getDateList()
			},
			//按照日期获取作业记录
			async getdata(data2, index) {
				const {
					success,
					msg,
					data
				} = await getById(data2);
				if (success) {
					this.dateList[index].data = data.records
				}

			},
		}
	}
</script>

<style>
	.floating-div {
		position: fixed;
		bottom: 10px;
		right: 10px;
		width: 80rpx;
		height: 80rpx;
		border-radius: 50%;
		background-color: #f2f2f2;

	}

	.car {
		animation: heightChange 1s forwards;
		/* 应用动画 */
	}

	@keyframes heightChange {
		0% {
			height: 2px;
			/* 初始高度 */
		}

		100% {
			height: auto;
			/* 结束高度 */
		}
	}
</style>